angular.module('SmartCanteenApp.windowSaleAnalyze', ['ngRoute', 'ngTouch'])

	.config(['$routeProvider', function($routeProvider) {
		$routeProvider.when('/windowSaleAnalyze', { // 档口营业差异分析
			templateUrl: 'newReports/windowSaleAnalyze.html',
			controller: 'windowSaleAnalyzeCtrl'
		});
	}])
	//餐卡信息列表
	.controller('windowSaleAnalyzeCtrl', ['$scope', '$timeout', '$filter', function($scope, $timeout, $filter) {
		$('#datepicker').daterangepicker({
			autoclose:true
		})
		$scope.searchDate = $scope.getNowFormatDate()+' 至 '+$scope.getNowFormatDate()
		$scope.postData = {
			itemNumberType:'0',
			period:'',
		}
		//请求所有档口
		$scope.getWindows = function(){
			$scope.getReport($scope.reportPath+'/commonLittleService/v1/allPeriodTime?canteenId='+$scope.canteenId,'','get',function(data){
				$scope.periods = data.data
			})
		}
		//get cId
		if( $scope.getCanteenId() != ''){
			$scope.canteenId =  $scope.getCanteenId() ;
		   	//获取基础数据
			$scope.getWindows();
		}
		$scope.$on('to-child', function(event,data) {
			//获取从父控制器传来的当前选中食堂
			$scope.canteenId = data;
			//获取基础数据
			$scope.getWindows();
		});
		//发送查询
		$scope.searchWindowSaleAnalyze = function(){
			var arr = $scope.searchDate.split(' 至 ')
			if($scope.postData.period == null){
				$scope.postData.period =''
			}
			let url = 'secondDetailService/v1/windowSaleAnalyze?canteenId='+$scope.canteenId+'&startDate='+arr[0]+'&endDate='+arr[1]+'&periodTimeId='+$scope.postData.period+'&itemNumberType='+$scope.postData.itemNumberType
			$scope.getReport($scope.reportPath+url,'','get',function(data){
				$scope.window_data_total = data.data
				$scope.window_data = data.data.window_data
				$scope.allWindow_data = data.data.window_data.concat()
				$scope.pagination($scope.window_data)
			})
			console.log(url)
//			$scope.window_data_total = {
//		        "window_data":[
//		            {
//		                "window_id":"",
//		                "window_name":"",
//		                "sale_money":1,
//		                "theory_sale_money":1,
//		                "cost":1,
//		                "theory_cost":1,
//		                "profit":1,
//		                "theory_profit":1
//		            },
//		            {
//		                "window_id":"",
//		                "window_name":"",
//		                "sale_money":1,
//		                "theory_sale_money":1,
//		                "cost":1,
//		                "theory_cost":1,
//		                "profit":1,
//		                "theory_profit":1
//		            }
//		        ],
//		        "sale_money_total":1,
//		        "theory_sale_money_total":1,
//		        "cost_total":1,
//		        "theory_cost_total":1,
//		        "profit_total":1,
//		        "theory_profit_total":1
//		    }
//			$scope.window_data = $scope.window_data_total.window_data
//			$scope.allWindow_data = $scope.window_data_total.window_data.concat()
//			$scope.pagination($scope.window_data)
	}
		//打印请求
		$scope.outPrint = function(){
			html = $("#tb_itemPreview")
			$scope.printHtml(html[0].innerHTML);
		}
	}])
